package com.miracle.设计模式.创建型模式.工厂方法模式.案例3_隐藏;

//抽象工厂
//重载多个创建方法，提供不同的创建方法
public class LoggerFactory2 {

    public void writeLog(Class<? extends Logger> cls){
        Logger logger = this.getLogger(cls);
        logger.writeLog();
    }

    public Logger getLogger(Class<? extends Logger> cls) {
        Logger logger = null;

        try {
            logger = (Logger) Class.forName(cls.getName()).newInstance();
        } catch (Exception e) {
            System.out.println("日志记录器创建失败");
            e.printStackTrace();
        }

        return logger;
    }
}
